from langchain_deepseek import ChatDeepSeek
from langchain.schema import (AIMessage, HumanMessage, SystemMessage)
from langchain.prompts import  (
    PromptTemplate, 
    ChatPromptTemplate, 
    HumanMessagePromptTemplate, 
    SystemMessagePromptTemplate,
    MessagesPlaceholder
)
from pydantic import BaseModel, Field


# template = PromptTemplate.from_template(template = "可以给我讲一个关于{subject}的故事")

# message = [
#     SystemMessage(content="你是葵花小课堂的智能教师"),
#     HumanMessage(content="我是小明"),
#     AIMessage(content="你好，小明"),
#     HumanMessage(content=template.format(subject="小白兔")),
# ]

# template = ChatPromptTemplate.from_messages([
#     SystemMessagePromptTemplate.from_template("你是{product}的{role}。你的名字叫{name}"),
#     HumanMessagePromptTemplate.from_template("{query}")
# ])

# prompt = template.format_messages(
#     product="葵花小课堂",
#     role="教师",
#     name="玲花",
#     query=PromptTemplate.from_template("可以给我讲一个关于{subject}的故事").format(subject="小白兔")
# )

# chat_prompt = ChatPromptTemplate.from_messages([
#     MessagesPlaceholder(variable_name="history"),
#     HumanMessagePromptTemplate.from_template("Translate your answer to {language}")
# ])

# prompt = chat_prompt.format_messages(
#     history = [
#         HumanMessage(content="你好，我是小明"),
#         AIMessage(content="你好小明，我是葵花小课堂的教师，玲花"),
#     ],
#     language="英文"
# )


# 定义结构化输出模型
class Date(BaseModel):
    year: int = Field(description="Year")
    month: int = Field(description="Month")
    day: int = Field(description="Day")
    era: str = Field(description="BC or AD")

# 初始化 LLM
llm = ChatDeepSeek(model="deepseek-chat", temperature=0)

# 定义结构化输出模型
structured_llm = llm.with_structured_output(Date)

prompt = PromptTemplate(
    template = """提取用户输入中的日期。
用户输入:
{query}"""
)

query = "2024年十二月23日天气晴..."

input_prompt = prompt.format_prompt(query = query)

print(prompt)
llm = ChatDeepSeek(model="deepseek-chat")
response = llm.invoke(prompt)
print(response.content)